package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;

public class P1144 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1144.class.getResource("P1144.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		StringTokenizer st = null;
		String line = stdin.readLine();
		while (line != null && !"0".equals(line)) {
			Integer N = Integer.valueOf(line.trim());
			Set<Integer>[] edges = new HashSet[N];
			for (int i = 0; i < N; i ++) {
				edges[i] = new HashSet<Integer>();
			}
			line = stdin.readLine();
			while (!"0".equals(line)) {
				st = new StringTokenizer(line);
				int u = Integer.valueOf(st.nextToken())-1;
				while (st.hasMoreTokens()) {
					int v = Integer.valueOf(st.nextToken())-1;
					edges[u].add(v);
					edges[v].add(u);
				}
				line = stdin.readLine();
			}
			
			int c = 0;
			int[] cut = cutPoints(N, edges);
			for (int u = 0; u < N; u ++) {
				if (cut[u] == 1) {
					c ++;
				}
			}
			System.out.println(c);

			line = stdin.readLine();
		}
	}
	
	private static int[] cutPoints(int N, Set<Integer>[] edges) {
		
		if (N == 1 || N == 2) return new int[N];
		
		DFSResult r = DFS(N, edges);
		int[] cut = new int[N];		//u是割点 <=> cut[u]=1
		//case 1, Root of DFS
		int root = -1;
		for (int i = 0; i < N; i ++) {
			if (r.p[i] == -1) {
				root = i;
				break;
			}
		}
		int t = 0;
		for (int i = 0; i < N; i ++) {
			if (r.p[i] == root) {
				t ++;
			}
		}
		//DFS的树根是割点，当且仅当子女数不少于2
		if (t >= 2) {
			cut[root] = 1;
		}
		
		//case 2, Other cut points (非根节点)
		//非根节点v是割点，当且仅当存在一个子女s, 不存在从s或者s的子孙到v的祖先的反向边。
		int[] low = new int[N];
		for (int u = 0; u < N; u ++) low[u] = r.d[u];
		
		for (int u = 0; u < N; u ++) {
			for (int w: edges[u]) {
				if (r.p[w] != u && r.p[u] != w 
						&& r.d[w] < r.d[u] && r.f[u] < r.f[w])	{	//反向边 u-w
					int v = u;
					while (v != w) {
						if (low[v] > r.d[w]) low[v] = r.d[w];
						v = r.p[v];
					}
				}
			}
		}

		for (int v = 0; v < N; v ++) {
			int u = r.p[v];
			if (v != root && u != root && low[v] >= r.d[u]) {
				cut[u] = 1;
			}
		}
//		for (int v = 0; v < N; v ++) {
//			System.out.println((v+1) + ":" + r.d[v] + "/" + r.f[v] + "$" + low[v]);
//		}
		//return
		return cut;
	}

	/**
	 * @param s
	 * @param N
	 * @param edges
	 */
	private static DFSResult DFS(int N, Set<Integer>[] edges) {
		
		char[] color = new char[N];
		int[] p = new int[N];
		int[] d = new int[N];
		int[] f = new int[N];
		for (int u = 0; u < N; u ++) {
			color[u] = 'w';
			p[u] = -1;
		}
		int time = 0;
		for (int i = 0; i < N; i ++) {
			if (color[i] == 'w') {	//start from u
				LinkedList<Integer> stack = new LinkedList<Integer>();
				stack.push(i);
				while (!stack.isEmpty()) {
					int u = stack.peek();
					if (color[u] == 'w') {
						color[u] = 'g';
						time ++;
						d[u] = time;
					}
					boolean find = false;
					for (int v: edges[u]) {
						if (color[v] == 'w') {
							stack.push(v);
							p[v] = u;
							find = true;
							break;
						}
					}
					if (!find) {
						u = stack.pop();
						color[u] = 'b';
						time ++;
						f[u] = time;
					}
				}
			}
		}
		
		//return 
		DFSResult r = new DFSResult();
		r.p = p;
		r.d = d;
		r.f = f;
		return r;
	}
	
	private static class DFSResult {
		int[] p;
		int[] d;
		int[] f;
	}
}